<?php if ( post_password_required() ) : ?>
	<p class="nopassword"><?php _e( 'This post is password protected. Enter the password to view any comments.' ); ?></p>
<!-- #comments -->
<?php
	return;
endif;
?>

<?php if ( have_comments() ) : ?>
	<div id="comments" class="cycle">
		<h3 id="comments-title"><span><?php comments_number('0', '1', '%' );?> 条评论</span><span class="add_comment">[ <a href="#respond"  rel="nofollow">发表评论</a> ]</span></h3>
	
		<ol class="commentlist">
			<?php wp_list_comments('type=all&callback=wwmm_comment'); ?>
		</ol>

<?php if ( get_comment_pages_count() > 1 && get_option( 'page_comments' ) ) : ?>
		<div class="page-bar">
			<?php paginate_comments_links('prev_next=0');?>
		</div>
<?php endif; ?>
	</div>
<?php elseif ( ! comments_open() && ! is_page() && post_type_supports( get_post_type(), 'comments' ) ) : ?>
	<p class="nocomments"><?php _e( 'Comments are closed.' ); ?></p>
<?php endif; ?>
	
<?php
if(get_option('T_smiley') == 'On') : ?>
<script type="text/javascript" language="javascript">
/* <![CDATA[ */
	function grin(tag) {
		var myField;
		tag = ' ' + tag + ' ';
		if (document.getElementById('comment') && document.getElementById('comment').type == 'textarea') {
			myField = document.getElementById('comment');
		} else {
			return false;
		}
		if (document.selection) {
			myField.focus();
			sel = document.selection.createRange();
			sel.text = tag;
			myField.focus();
		}
		else if (myField.selectionStart || myField.selectionStart == '0') {
			var startPos = myField.selectionStart;
			var endPos = myField.selectionEnd;
			var cursorPos = endPos;
			myField.value = myField.value.substring(0, startPos)
						  + tag
						  + myField.value.substring(endPos, myField.value.length);
			cursorPos += tag.length;
			myField.focus();
			myField.selectionStart = cursorPos;
			myField.selectionEnd = cursorPos;
		}
		else {
			myField.value += tag;
			myField.focus();
		}
	}
/* ]]> */
</script>
<?php
$tpurl = get_template_directory_uri();
$smilies = '<div class="smiley cycle">
	<a title="嘿" class="hov-tip" href="javascript:grin(\':mrgreen:\')"><img src="'.$tpurl.'/smilies/icon_mrgreen.gif" /></a> 
	<a title="色" class="hov-tip" href="javascript:grin(\':razz:\')"><img src="'.$tpurl.'/smilies/icon_razz.gif" /></a> 
	<a title="悲" class="hov-tip" href="javascript:grin(\':sad:\')"><img src="'.$tpurl.'/smilies/icon_sad.gif" /></a> 
	<a title="笑" class="hov-tip" href="javascript:grin(\':smile:\')"><img src="'.$tpurl.'/smilies/icon_smile.gif" /></a> 
	<a title="惊" class="hov-tip" href="javascript:grin(\':oops:\')"><img src="'.$tpurl.'/smilies/icon_redface.gif" /></a> 
	<a title="亲" class="hov-tip" href="javascript:grin(\':grin:\')"><img src="'.$tpurl.'/smilies/icon_biggrin.gif" /></a> 
	<a title="雷" class="hov-tip" href="javascript:grin(\':eek:\')"><img src="'.$tpurl.'/smilies/icon_surprised.gif" /></a> 
	<a title="晕" class="hov-tip" href="javascript:grin(\':???:\')"><img src="'.$tpurl.'/smilies/icon_confused.gif" /></a> 
	<a title="酷" class="hov-tip" href="javascript:grin(\':cool:\')"><img src="'.$tpurl.'/smilies/icon_cool.gif" /></a> 
	<a title="奸" class="hov-tip" href="javascript:grin(\':lol:\')"><img src="'.$tpurl.'/smilies/icon_lol.gif" /></a> 
	<a title="怒" class="hov-tip" href="javascript:grin(\':mad:\')"><img src="'.$tpurl.'/smilies/icon_mad.gif" /></a> 
	<a title="狂" class="hov-tip" href="javascript:grin(\':twisted:\')"><img src="'.$tpurl.'/smilies/icon_twisted.gif" /></a> 
	<a title="萌" class="hov-tip" href="javascript:grin(\':roll:\')"><img src="'.$tpurl.'/smilies/icon_rolleyes.gif" /></a> 
	<a title="吃" class="hov-tip" href="javascript:grin(\':wink:\')"><img src="'.$tpurl.'/smilies/icon_wink.gif" /></a> 
	<a title="贪" class="hov-tip" href="javascript:grin(\':idea:\')"><img src="'.$tpurl.'/smilies/icon_idea.gif" /></a> 
	<a title="囧" class="hov-tip" href="javascript:grin(\':arrow:\')"><img src="'.$tpurl.'/smilies/icon_arrow.gif" /></a> 
	<a title="羞" class="hov-tip" href="javascript:grin(\':neutral:\')"><img src="'.$tpurl.'/smilies/icon_neutral.gif" /></a> 
	<a title="哭" class="hov-tip" href="javascript:grin(\':cry:\')"><img src="'.$tpurl.'/smilies/icon_cry.gif" /></a> 
	<a title="汗" class="hov-tip" href="javascript:grin(\':?:\')"><img src="'.$tpurl.'/smilies/icon_question.gif" /></a> 
	<a title="宅" class="hov-tip" href="javascript:grin(\':evil:\')"><img src="'.$tpurl.'/smilies/icon_evil.gif" /></a> 
	<a title="馋" class="hov-tip" href="javascript:grin(\':shock:\')"><img src="'.$tpurl.'/smilies/icon_eek.gif" /></a> 
	<a title="槑" class="hov-tip" href="javascript:grin(\':!:\')"><img src="'.$tpurl.'/smilies/icon_exclaim.gif" /></a>
</div>';
endif;

function wwmm_fields($fields) {
	$commenter = wp_get_current_commenter();
	$req = get_option( 'require_name_email' );
	$aria_req = ( $req ? " aria-required='true'" : '' );
    $fields =  array(
        'author' => '<p class="comment-form-field comment-form-author">' .
                    '<input id="author" name="author" type="text" value="' . esc_attr( $commenter['comment_author'] ) . '" size="30"' . $aria_req . ' /><label for="author">姓名</label> <span class="required">必填</span></p>',
        'email'  => '<p class="comment-form-field comment-form-email">' .
                    '<input id="email" name="email" type="text" value="' . esc_attr(  $commenter['comment_author_email'] ) . '" size="30"' . $aria_req . ' /><label for="email">邮箱</label> <span class="required">必填，不会被公开</span></p>',
        'url'    => '<p class="comment-form-field comment-form-url">' .
                    '<input id="url" name="url" type="text" value="' . esc_attr( $commenter['comment_author_url'] ) . '" size="30" /><label for="url">网站</label> <span class="tip">可以是微博、博客、空间等</span></p>',
    );
	return $fields;
}
add_filter('comment_form_default_fields','wwmm_fields');

if(get_option('T_smiley') != 'On') $smilies=''; else $smilies;
$args = array(
	'comment_field'			=> $smilies.'<p class="comment-form-comment"><textarea aria-required="true" rows="8" cols="45" name="comment" id="comment" onkeydown="if(event.ctrlKey){if(event.keyCode==13){document.getElementById(\'submit\').click();return false}};"></textarea></p>',
	'label_submit'			=> '发表评论 / Ctrl+Enter',
	'form-allowed-tags'		=> '',
	'comment_notes_before'	=>  '',
	'comment_notes_after'	=>  '',
);
comment_form($args); 
?>
